package com.mine.distinctionteam.ui.home.adapter;
import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.mine.distinctionteam.R;
import com.mine.distinctionteam.bean.home.HomeDatasBean;
import java.util.List;
/**
 *
 */
public class ItemListViewAdapter extends BaseAdapter {
    private Context mContext;
    private List<HomeDatasBean> list;
    private LayoutInflater inflater;
    private ItemListViewRecyclerViewAdapter itemListViewRecyclerViewAdapter;

    public ItemListViewAdapter(Context mContext, List<HomeDatasBean> list) {
        this.mContext = mContext;
        this.list = list;
        inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {

            return list.get(position);
    }
    @Override
    public long getItemId(int position) {
            return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_fragment_home_listview, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        LinearLayoutManager manager=new LinearLayoutManager(mContext);
        manager.setOrientation(LinearLayoutManager.HORIZONTAL);
        viewHolder.recyclerView_item_fragment_home_listView.setLayoutManager(manager);
        itemListViewRecyclerViewAdapter = new ItemListViewRecyclerViewAdapter(mContext, list.get(position).getItems());
        //设置适配器
        viewHolder.recyclerView_item_fragment_home_listView.setAdapter(itemListViewRecyclerViewAdapter);
        //设置recyclerView横向滚动

        viewHolder.textView_item_fragment_home_listView_chinese_bag_title.setText(list.get(position).getAlbum().getTitle());
        Glide.with(mContext).load(list.get(position).getAlbum().getImage()).into(viewHolder.imageView_item_fragment_home_listView);
        viewHolder.textView_item_fragment_home_listView_bag_subTitle.setText(list.get(position).getAlbum().getSubTitle());
        if ((list.get(position).getAlbum().getTag()).equals("闲置")) {
            viewHolder.textView_item_fragment_home_listView_free.setText(list.get(position).getAlbum().getTag());
            viewHolder.textView_item_fragment_home_listView_bag_subTitle.setVisibility(View.GONE);
        }
        if ((list.get(position).getAlbum().getTag()).equals("海淘")) {
            viewHolder.textView_item_fragment_home_listView_bag_subTitle.setText(list.get(position).getAlbum().getTag());
            viewHolder.textView_item_fragment_home_listView_free.setVisibility(View.GONE);
        }

        return convertView;
    }

    class ViewHolder {
        private ImageView imageView_item_fragment_home_listView;
        private RecyclerView recyclerView_item_fragment_home_listView;
        //闲置
        private TextView textView_item_fragment_home_listView_free;
        //海淘
        private TextView textView_item_fragment_home_listView_sea;
        private TextView textView_item_fragment_home_listView_chinese_bag_title;
        private TextView textView_item_fragment_home_listView_bag_subTitle;

        public ViewHolder(View convertView) {
            imageView_item_fragment_home_listView = (ImageView) convertView.findViewById(R.id.imageView_item_fragment_home_listView);
            recyclerView_item_fragment_home_listView = (RecyclerView) convertView.findViewById(R.id.recyclerView_item_fragment_home_listView);
            textView_item_fragment_home_listView_free = (TextView) convertView.findViewById(R.id.textView_item_fragment_home_listView_free);
            textView_item_fragment_home_listView_sea = (TextView) convertView.findViewById(R.id.textView_item_fragment_home_listView_sea);
            textView_item_fragment_home_listView_chinese_bag_title = (TextView) convertView.findViewById(R.id.textView_item_fragment_home_listView_chinese_bag_title);
            textView_item_fragment_home_listView_bag_subTitle = (TextView) convertView.findViewById(R.id.textView_item_fragment_home_listView_bag_subTitle);
        }
    }
}
